package com.zf.lease.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.lease.domain.CustomerContract;
import com.zf.lease.service.ICustomerContractService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;

/**
 * 用户和契约的关系Controller
 * 
 * @author ruoyi
 * @date 2024-10-07
 */
@RestController
@RequestMapping("/lease/customer_contract")
public class CustomerContractController extends BaseController
{
    @Autowired
    private ICustomerContractService customerContractService;

    /**
     * 查询用户和契约的关系列表
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerContract customerContract)
    {
        startPage();
        List<CustomerContract> list = customerContractService.selectCustomerContractList(customerContract);
        return getDataTable(list);
    }

    /**
     * 导出用户和契约的关系列表
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:export')")
    @Log(title = "用户和契约的关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerContract customerContract)
    {
        List<CustomerContract> list = customerContractService.selectCustomerContractList(customerContract);
        ExcelUtil<CustomerContract> util = new ExcelUtil<CustomerContract>(CustomerContract.class);
        util.exportExcel(response, list, "用户和契约的关系数据");
    }

    /**
     * 获取用户和契约的关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(customerContractService.selectCustomerContractByContractId(contractId));
    }

    /**
     * 新增用户和契约的关系
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:add')")
    @Log(title = "用户和契约的关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerContract customerContract)
    {
        return toAjax(customerContractService.insertCustomerContract(customerContract));
    }

    /**
     * 修改用户和契约的关系
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:edit')")
    @Log(title = "用户和契约的关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerContract customerContract)
    {
        return toAjax(customerContractService.updateCustomerContract(customerContract));
    }

    /**
     * 删除用户和契约的关系
     */
    @PreAuthorize("@ss.hasPermi('lease:customer_contract:remove')")
    @Log(title = "用户和契约的关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(customerContractService.deleteCustomerContractByContractIds(contractIds));
    }
}
